package io.zhifei.modules.sys.system.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.zhifei.common.annotation.SysLog;
import io.zhifei.common.utils.R;
import io.zhifei.modules.sys.system.entity.ExaminationEntity;
import io.zhifei.modules.sys.system.service.ExaminationServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * 备考咨询管理
 *
 * @ClassNameExaminationController
 * @Description
 * @Author
 * @Date2020/11/16 15:03
 * @Version V1.0
 **/
@CrossOrigin //跨域
@RestController
@RequestMapping("/sys/examination")
@Api(value = "examination", description = "备考咨询管理")
public class SysExaminationController extends AbstractController {

    @Autowired
    private ExaminationServer examinationServer;

    @GetMapping("/list")
    @ApiOperation("备考咨询列表")
    public R list(@ApiParam(name = "page", value = "页码", required = true) @RequestParam Integer page,
                  @ApiParam(name = "pageSize", value = "每页大小", required = true) @RequestParam Integer pageSize,
                  @ApiParam(name = "type", value = "发布类型", required = true) @RequestParam Integer type) {
        try {
            return R.ok().put("data", examinationServer.getlist(page, pageSize, type));
        } catch (Exception e) {
            return R.error(e.getMessage());
        }
    }

    @SysLog("新增备考咨询")
    @PostMapping("/add")
    @ApiOperation("新增备考咨询")
    public R add(@RequestBody ExaminationEntity examinationEntity) {
        try {
            examinationServer.add(examinationEntity, getUserId());
            return R.ok("新增成功！");
        } catch (Exception e) {
            return R.error(e.getMessage());
        }
    }

    @SysLog("编辑备考咨询")
    @PostMapping("/update")
    @ApiOperation("编辑咨询列表")
    public R update(@RequestBody ExaminationEntity examinationEntity) {
        try {
            examinationServer.update(examinationEntity, getUserId());
            return R.ok("编辑成功！");
        } catch (Exception e) {
            return R.error( e.getMessage());
        }
    }

    @SysLog("删除备考咨询")
    @PostMapping("/delete")
    @ApiOperation("删除咨询列表")
    public R delete(@ApiParam(name = "ids", value = "删除的id数组", required = true)String ids) {
        try {
            examinationServer.delete(ids.split(","));
            return R.ok("删除成功！");
        } catch (Exception e) {
            return R.error( e.getMessage());
        }
    }
}